package com.example.nettyRpc.client;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.AttributeKey;

public class MyClient {
	public static void main(String[] args) throws Exception {
		EventLoopGroup Group = new NioEventLoopGroup();
		try {
			Bootstrap sb = new Bootstrap();
			sb.group(Group)
				//.option(ChannelOption.SO_BACKLOG, 128)
				.option(ChannelOption.SO_KEEPALIVE, true)
				.channel(NioSocketChannel.class)
				.handler(new MyClientInitializer());
			ChannelFuture cf = sb.connect("localhost",8899).sync();
// -----------------发送数据-------------------------
			cf.channel().writeAndFlush("hello server \r\n");
// -----------------把netty服务器注册到zookeeper上-------------------------
//			// 1、连接zookeeper
//			CuratorFramework client = ZookeeperFactory.create();
//
//			// 2、监听服务器节点
//			Listenable<CuratorListener>  cl= client.getCuratorListenable();
//
// -------------------------------------------------------------------


			cf.channel().closeFuture().sync();
			Object obj = cf.channel().attr(AttributeKey.valueOf("sss")).get();
			System.out.println("获取到数据："+obj);
		} catch (InterruptedException e) {
				e.printStackTrace();
			}finally {
				Group.shutdownGracefully();

			}
	}
}
